<?php
/**
 * Created by PhpStorm.
 * User: Liuhongchuan
 * Date: 2018/5/2
 * Time: 09:27
 * 设备验证记录
 */
namespace app\operation\controller;

use app\common\controller\OperationBase;

class ErrorImg extends OperationBase {

	public function _initialize() {
		parent::_initialize();  
    }

	public function index() {
	    $auth_group = sp_get_auth_menu_3("20061006");
        $shops = db("shop")->where(array("parent_id" => array("neq", 0)))->order("parent_id desc, shop_name desc")->column("id, shop_name");
        $this->assign("shops", $shops);
        $this->assign("menus", $auth_group);
        echo $this->fetch();
	}

	public function ajaxIndex() {

        $member_name = input("member_name/s");
        $member_mobile = input("member_mobile/s");
        $pt_name = input("pt_name/s");
        $pt_mobile = input("pt_mobile/s");
        $shop_id = input("shop_id/d");
        $draw = input("draw",0) + 1;//请求时间
        $start = input("start/s");
        $end = input("end/s");

        if (!empty($member_name)) {
            $where["r.member_name"] = array("like", "%{$member_name}%");
        }
        if (!empty($member_mobile)) {
            $where["r.member_mobile"] = array("like", "%{$member_mobile}%");
        }
        if (!empty($pt_name)) {
            $where["r.pt_name"] = array("like", "%{$pt_name}%");
        }
        if (!empty($pt_mobile)) {
            $where["r.pt_mobile"] = array("like", "%{$pt_mobile}%");
        }
        if (!empty($shop_id)) {
            $where["r.shop_id"] = array("eq", $shop_id);
        }
        if (empty($start)) {
            $start = date('Y-m-d') . " 00:00:00";
        } else {
            $start = $start . " 00:00:00";
        }
        if (empty($end)) {
            $end = date('Y-m-d') . " 23:59:59";
        }else{
            $end = $end . " 23:59:59";
        }
        if ($end < $start) {
            $this->error("起始时间不能大于结束时间");
        }
        $where["r.create_time"] = array("between time", array($start, $end));

        $total = db("ErrorImg")->alias("r")->where($where)->count(1);
        $list = db("ErrorImg")->alias("r")
            ->join("m_shop s", "s.id = r.shop_id", "left")
            ->field("r.*, s.shop_name")
            ->where($where)
            ->order($this->get_order())
            ->limit($this->get_limit())
            ->select();

        $data = array('pageData' => $list, 'total' => $total, "draw" => $draw);
		$this->ajax($data);
	}
}
